package com.bjpowernode.web.advice;

import com.bjpowernode.commons.exception.YLBException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.util.HashMap;
import java.util.Map;

@RestControllerAdvice // 控制器的增强
public class EXAdvice {
    // 代码中考虑到的业务异常
    @ExceptionHandler(YLBException.class)
    public Map re(Exception e) {
        e.printStackTrace();
        String message = e.getMessage();
        Map result = new HashMap();
        result.put("success", false);
        result.put("message", message);
        return result;
    }

    // 未知错误！
    @ExceptionHandler(Exception.class)
    public Map e(Exception e) {
        e.printStackTrace();
        Map result = new HashMap();
        result.put("success", false);
        result.put("message", "系统忙！请稍后再试...");
        return result;
    }

}
